<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	$(function() {
		$("#div_attr").hide();
		$("#btn_add_attr_item")
				.click(
						function() {
							$("#attr_list")
									.append(
											'<div class="controls">'
													+ '<input type="hidden" name="attrs" value="'
													+ $("#attr_item").val()
															.trim()
													+ '">'
													+ '<input type="hidden" name="types" value="'
													+ $(
															"#attr_type option:selected")
															.val()
													+ '">'
													+ '<code>'
													+ $(
															"#attr_type option:selected")
															.text()
													+ "&nbsp;&nbsp;"
													+ $("#attr_item").val()
															.trim()
													+ '</code><button style="margin-left:50px;margin-bottom:5px" type="button" class="btn" onclick="deltr(this)">删除</button></div>');
							$("#div_attr").hide();
							$("#attr_item").val("");
						});
	});
	function deltr(delbtn) {
		$(delbtn).parents(".controls").remove();
	}

	function hide_show_attr() {
		$("#div_attr").toggle("normal");
	}
	function valid() {
		$("#help_type").val("");
		$("#div_type").removeClass("control-group error");
		$("#div_type").addClass("control-group");
		var name = $("#type").val().trim();
		if (name == "") {
			$("#div_type").removeClass("control-group");
			$("#div_type").addClass("control-group error");
			document.getElementById("help_type").innerHTML = "类别名称不能为空";
			return false;
		}
		return true;
	}
	function goback() {
		history.go(-1);
	}
</script>
<div class="page-header">
	<h3 style="margin-top: auto">新增航电设备类别</h3>
</div>
<div class="row-fluid">
	<div>
		<form class="form-horizontal"
			action="<%=request.getContextPath()%>/domain_entity/equipment/category/add"
			method="POST" onsubmit="return valid()">
			<div class="control-group" id="div_type">
				<label class="control-label">类别名称</label>
				<div class="controls">
					<input type="text" placeholder="类别名称" id="type" name="type">
					<span class="help-inline" id="help_type"></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">描述信息</label>
				<div class="controls">
					<textarea rows="3" class="input-xxlarge" placeholder="描述信息"
						id="description" name="description"></textarea>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">属性列表</label>
				<div id="attr_list"></div>
				<div class="controls">
					<button type="button" class="btn" id="btn_add_attr"
						onclick="hide_show_attr()"><i class="icon-plus"></i>&nbsp;添加属性</button>
				</div>
			</div>
			<c:choose>
				<c:when test="${!empty typeList}">
					<div class="control-group" id="div_attr">
						<div class="controls">
							<div class="form-inline">
								属性类型&nbsp;&nbsp;<select style="width: 200px" id="attr_type">
									<c:forEach items="${typeList}" var="item">
										<option value="${item.id}">
											<c:out value="${item.name}" />
										</option>
									</c:forEach>
								</select> <input type="text" class="input-medium" placeholder="属性名称"
									id="attr_item">
								<button type="button" class="btn" id="btn_add_attr_item"><i class="icon-plus"></i>&nbsp;添加</button>
							</div>
						</div>
					</div>
				</c:when>
			</c:choose>

			<div class="control-group">
				<div class="controls">
					<button type="submit" class="btn" id="submit"><i class="icon-ok"></i>&nbsp;提交</button>
					<button type="button" class="btn" style="margin-left=50px;" onclick="goback()"><i class="icon-remove"></i>&nbsp;取消</button>
				</div>
			</div>
		</form>
	</div>
</div>
<!--/row-->